package site.lyun.dao;

import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import site.lyun.entity.User;

import java.util.List;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
    @Override
    public void rigister(User user) {
        HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
        hibernateTemplate.saveOrUpdate(user);
    }

    @Override
    public User find(User user) {
        User u = null;
        HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
        List<User> list = (List<User>) hibernateTemplate.find("from User where userName=?",user.getUserName());
        if(list.size()!=0){
            u = list.get(0);
        }
        return u;
    }
}
